<template>
  <a-layout-header :class="[headerTheme, 'admin-header']">
    <a-row>
      <!-- logo区 -->
      <a-col :span="4" class="logo-style">
        <div :class="['logo', theme]">
          <router-link to="/home">
            <img src="../../assets/jss.png" />
            <!-- <h1>{{ systemName }}</h1> -->
          </router-link>
        </div>
      </a-col>
      <!-- 顶部菜单区 -->
      <a-col :span="14">
        <!-- <i-menus
        mode="horizontal"
        :openKeys="openKeys"
        @openChange="onOpenChange"
        :theme="theme"
        :collapsed="collapsed"
        :options="menuData"
        @select="onSelect"
        class="top_menu_style" /> -->
      </a-col>
      <!-- 搜素消息登录区 -->
      <a-col :span="6">
        <div :class="['admin-header-wide', layout, pageWidth]">
          <router-link v-if="isMobile || layout === 'head'" to="/"
            :class="['logo', isMobile ? null : 'pc', headerTheme]">
            <img width="32" src="@/assets/img/logo.png" />
            <h1 v-if="!isMobile">{{ systemName }}</h1>
          </router-link>
          <a-divider v-if="isMobile" type="vertical" />
          <a-icon v-if="layout !== 'head'" class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'"
            @click="toggleCollapse" style="display: none" />
          <!-- <div
            v-if="layout !== 'side' && !isMobile"
            class="admin-header-menu"
            :style="`width: ${menuWidth};`"
          >
            <i-menu
              class="head-menu"
              :theme="headerTheme"
              mode="horizontal"
              :options="menuData"
              @select="onSelect"
            />
          </div> -->
          <div :class="['admin-header-right', headerTheme]">
            <!-- <header-search class="header-item" @active="(val) => (searchActive = val)" /> -->
            <div class="header-item">
              <a-icon type="team" /> 登录账号：<span style="font-weight: bold;">杨明</span>
            </div>
            <div class="header-item">
              <a-icon type="bank" /> 用户单位：<span style="font-weight: bold;">教育学院</span>
            </div>
            <div class="header-item" @click="logout">
              <a-icon type="poweroff" /> <a-button type="link">
                退出登录
              </a-button>
            </div>
            <!-- <a-tooltip class="header-item" title="大屏" placement="bottom"> -->
              <!-- <a href="http://10.176.1.11" target="_blank">
              <a-icon type="home" />
            </a> -->
            <!-- </a-tooltip> -->
           
            <!-- <header-notice class="header-item" /> -->
            <!-- <header-avatar class="header-item" /> -->
            <!-- <a-dropdown class="lang header-item">
            <div>
              <a-icon type="global"/> {{langAlias}}
            </div>
            <a-menu @click="val => setLang(val.key)" :selected-keys="[lang]" slot="overlay">
              <a-menu-item v-for=" lang in langList" :key="lang.key">{{lang.key.toLowerCase() + ' ' + lang.name}}</a-menu-item>
            </a-menu>
          </a-dropdown> -->
          </div>
        </div>
      </a-col>
    </a-row>
  </a-layout-header>
</template>

<script>
import IMenus from '@/components/menu/menu'
import HeaderSearch from "./HeaderSearch";
import HeaderNotice from "./HeaderNotice";
import HeaderAvatar from "./HeaderAvatar";
import IMenu from "@/components/menu/menu";
import { mapState, mapMutations } from "vuex";
import {logout} from '@/services/user'

export default {
  name: "AdminHeader",
  components: { IMenu, HeaderAvatar, HeaderNotice, HeaderSearch, IMenus },
  props: ["collapsed", "menuData"],
  data() {
    return {
      langList: [
        { key: "CN", name: "简体中文", alias: "简体" },
        { key: "HK", name: "繁體中文", alias: "繁體" },
        { key: "US", name: "English", alias: "English" },
      ],
      searchActive: false,
    };
  },
  computed: {
    ...mapState("setting", [
      "theme",
      "isMobile",
      "layout",
      "systemName",
      "lang",
      "pageWidth",
    ]),
    headerTheme() {
      if (
        this.layout == "side" &&
        this.theme.mode == "dark" &&
        !this.isMobile
      ) {
        return "light";
      }
      return this.theme.mode;
    },
    langAlias() {
      let lang = this.langList.find((item) => item.key == this.lang);
      return lang.alias;
    },
    menuWidth() {
      const { layout, searchActive } = this;
      const headWidth = layout === "head" ? "100% - 188px" : "100%";
      const extraWidth = searchActive ? "600px" : "400px";
      return `calc(${headWidth} - ${extraWidth})`;
    },
  },
  methods: {
    logout() {
      logout()
      this.$router.push('/login')
    },
    toggleCollapse() {
      this.$emit("toggleCollapse");
    },
    onSelect(obj) {
      this.$emit("menuSelect", obj);
    },
    ...mapMutations("setting", ["setLang"]),
  },
};
</script>

<style lang="less" scoped>
@import "index";

.logo-style {
  img {
    display: inline-block;
    // width: 48px;
    height: 50px;
    margin-top: -8px;
    margin-left: 8px;
  }

  h1 {
    display: inline-block;
    margin-left: 10px;
    font-size: 1.5em;
    color: #fff;
    letter-spacing: 3px;
  }
}

.top_menu {
  height: 65px;
  background-color: #5090F4;
}

.top_menu_style {}

.ant-menu-dark,
.ant-menu-dark .ant-menu-sube {
  background-color: none !important;
}

.ant-menu-dark {
  background-color: none !important;
}
</style>
